package br.com.lucasddaniel.merchanmobile.util;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import br.com.lucasddaniel.merchanmobile.R;

public class FilterTextWatcher implements TextWatcher {

	private ArrayAdapter<? extends Object> adapter;
	@SuppressWarnings( "unused" )
	private EditText searchBox;
	@SuppressWarnings( "unused" )
	private int label;

	public FilterTextWatcher( ArrayAdapter<? extends Object> adapter ) {
		this.adapter = adapter;
	}

	public FilterTextWatcher( final ArrayAdapter<? extends Object> adapter, final EditText searchBox, final int label ) {
		this.adapter = adapter;
		this.label = label;
		this.searchBox = searchBox;
		searchBox.setHint( adapter.getContext().getResources().getString( label ) );
		searchBox.setTextColor( adapter.getContext().getResources().getColor( R.color.txtview_gray ) );
	}

	public void afterTextChanged( Editable s ) {
	}

	public void beforeTextChanged( CharSequence s, int start, int count, int after ) {
	}

	public void onTextChanged( CharSequence s, int start, int before, int count ) {
		adapter.getFilter().filter( s.toString().trim() );
	}
}
